package ar.com.poo.vista;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

import ar.com.poo.controlador.GestionTelefonia;
import ar.com.poo.modelo.Consumo;
import ar.com.poo.modelo.Servicio;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class LiquidacionConsumos extends javax.swing.JFrame {

	private static LiquidacionConsumos app;
	private JTable jTableConsumo;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				LiquidacionConsumos inst = new LiquidacionConsumos();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);

			}
		});
	}

	public static LiquidacionConsumos getInstancia() {
		if (app == null)
			app = new LiquidacionConsumos();
		return app;
	}

	public LiquidacionConsumos() {
		super();
		initGUI();
	}

	private void initGUI() {
		
		try {
			{
				getContentPane().setLayout(null);
				getContentPane().add(getJTableConsumo());

				
			}
			{
				this.setSize(546, 186);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private JTable getJTableConsumo() {
		if(jTableConsumo == null) {
			
						
			DefaultTableModel  modelo = new DefaultTableModel();
			
			modelo.addColumn("fecha");
			modelo.addColumn("consumo");
			modelo.addColumn("usuario");
			
			jTableConsumo = new JTable(modelo);
			getFilas(modelo);

			jTableConsumo.setBounds(139, 37, 283, 110);
		}
		return jTableConsumo;
	}

	
	
	private void getFilas(DefaultTableModel  modelo){
		
		GestionTelefonia sist = GestionTelefonia.getInstancia();		
		
		Collection<Consumo> consumos = sist.liquidarConsumos();
		
		ArrayList<ArrayList> dataTable = new ArrayList<ArrayList>();
		
		for (Iterator iterator = consumos.iterator(); iterator.hasNext();) {
			Consumo consumo = (Consumo) iterator.next();
			
			ArrayList row =  new ArrayList();
			row.add(consumo.getFecha());
			row.add(consumo.getTotal());
			row.add(consumo.getUsuario());

			dataTable.add(row);
		}
			
		Collection<ArrayList> filas = dataTable;
		
		int i = 0;
		for (Iterator iterator = filas.iterator(); iterator.hasNext();) {
			ArrayList fila = (ArrayList) iterator.next();
			modelo.insertRow(i, fila.toArray());
			i++;
		}
		
		
	}
	
}
